<div class="message-form">
    <h3 class="popup-title">Написать<br /> генеральному директору</h3>
    <div class="message-form__inner">
        <?php
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'write-form',
            'action' => '/main/ajax/message',
            'enableClientValidation' => true,
            'clientOptions' => array(
                'validateOnSubmit' => true,
            ),
        ));
        ?>
        <div style="display: none">
            <?php echo $form->error($model, 'userName'); ?>
            <?php echo $form->error($model, 'userPhone'); ?>
            <?php echo $form->error($model, 'message'); ?>
            <?php echo $form->error($model, 'email'); ?>
            <?php echo $form->error($model, 'number'); ?>
        </div>
        <fieldset>
            <div class="type-text">
                <?php echo $form->textField($model, 'userName', array('placeholder' => 'Ваше имя')); ?>	
            </div>
        </fieldset>
        <fieldset>
            <div class="type-text">
                <?php echo $form->textField($model, 'userPhone', array('placeholder' => 'Ваш телефон', 'class' => 'masked-phone')); ?>
            </div>
        </fieldset>
        <fieldset>
            <div class="type-text">
                <?php echo $form->textField($model, 'email', array('placeholder' => 'Ваш E-mail')); ?>
            </div>
        </fieldset>
        <fieldset>
            <div class="type-text">
                <?php echo $form->textField($model, 'number', array('placeholder' => 'Ваш номер заказа')); ?>
            </div>
        </fieldset>
        <fieldset>
            <div class="textarea">
                <?php echo $form->textArea($model, 'message', array('placeholder' => 'Сообщение', 'cols' => 45, 'rows' => 10)); ?>				
            </div>
        </fieldset>
        <fieldset>
            <div class="type-submit">
                <?php echo CHtml::submitButton('Отправить'); ?>				
            </div> 
        </fieldset>
        <script type="text/javascript">
            /*&lt;![CDATA[*/
            $(document).ready(function () {
                jQuery("#WriteDirectorForm_userPhone").mask("+7 (999) 999-99-99");
                jQuery('#write-form').yiiactiveform({'validateOnSubmit': true,
                    'afterValidate':
                            function (form, data, hasError) {
                                if (!hasError) {
                                    $.ajax({
                                        type: "POST",
                                        url: form[0].action,
                                        data: $(form).serialize(),
                                        success: function (ret) {
                                            $('.fancybox-close').trigger('click');
                                            var data = JSON.parse(ret);
                                            mobi03.showMessage(data.message.title, data.message.desc);
                                        }
                                    });
                                }
                            }
                    ,
                    'attributes': [{
                            'id': 'WriteDirectorForm_userName',
                            'inputID': 'WriteDirectorForm_userName',
                            'errorID': 'WriteDirectorForm_userName_em_',
                            'model': 'WriteDirectorForm', 'name': 'userName',
                            'enableAjaxValidation': false,
                            'clientValidation': function (value, messages, attribute) {
                                if (jQuery.trim(value) == '') {
                                    messages.push("\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u00abUser Name\u00bb.");
                                }
                            }}, {'id': 'WriteDirectorForm_userPhone', 'inputID': 'WriteDirectorForm_userPhone', 'errorID': 'WriteDirectorForm_userPhone_em_', 'model': 'WriteDirectorForm', 'name': 'userPhone', 'enableAjaxValidation': false, 'clientValidation': function (value, messages, attribute) {
                                if (jQuery.trim(value) == '') {
                                    messages.push("\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u00abUser Phone\u00bb.");
                                }
                            }}, {'id': 'WriteDirectorForm_message', 'inputID': 'WriteDirectorForm_message', 'errorID': 'WriteDirectorForm_message_em_', 'model': 'WriteDirectorForm', 'name': 'message', 'enableAjaxValidation': false, 'clientValidation': function (value, messages, attribute) {
                                if (jQuery.trim(value) == '') {
                                    messages.push("\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u00abMessage\u00bb.");
                                }
                            }}], 'errorCss': 'error'});
            });
            /*]]&gt;*/
        </script>
        <?php $this->endWidget(); ?>
    </div>
</div>
